package com.protocols.sctp.m3ua.sccp.tcap.map;

import java.io.Serializable;

import com.protocols.BCDNumber;
import com.protocols.OctaveInteger;
import com.protocols.ProtoOperations;
import com.protocols.ProtocolStackException;
import com.protocols.sctp.m3ua.sccp.tcap.TcapBegin;
import com.protocols.sctp.m3ua.sccp.tcap.TcapConstructor;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitByteArray;
import com.protocols.sctp.m3ua.sccp.tcap.TcapPrimitiveUnitNumber;

public class AnyTimeInterrogation extends MapInvoke implements Serializable{
	
	private TcapConstructor SubscriberIdentityContainer = new TcapConstructor(0xa0);
	private TcapPrimitiveUnitByteArray IMSI= new TcapPrimitiveUnitByteArray(0x80);
	private TcapPrimitiveUnitByteArray MSISDN = new TcapPrimitiveUnitByteArray(0x81);
	private TcapConstructor RequestedInfoContainer = new TcapConstructor(0xa1);
	private TcapPrimitiveUnitNumber IMSI= new TcapPrimitiveUnitNumber(0x80);
	private TcapPrimitiveUnitNumber MSISDN = new TcapPrimitiveUnitNumber(0x81);
	
	
	
	public AnyTimeInterrogation() {
		super();		
		super.Parameters.addElement(SubscriberIdentityContainer);
		SubscriberIdentityContainer.addElement(IMSI);
		SubscriberIdentityContainer.addElement(MSISDN);
		super.Parameters.addElement(RequestedInfoContainer);
		
	}
	
	public String getIMSI() {		
		byte [] val = IMSI.getTagValue();		
		int i=0;
		String value="";
		while (i<val.length){
			value+=(val[i] & 0b00001111);
			value+=(val[i] & 0b11110000)>>4;
			i++;			
		}			
		return value;

	}

	public void setIMSI(String iMSI) {
		BCDNumber imsi = new BCDNumber(iMSI, "f");			
		IMSI.setTagValue(imsi.getByteArray());
		MSISDN.setVisible(false);
	}

	public String getMSISDN() {
		
		byte [] val = MSISDN.getTagValue();
		
		if (val.length>1){
			int i=1;
			String value="";
			while (i<val.length){
				value+=(val[i] & 0b00001111);
				value+=(val[i] & 0b11110000)>>4;
				i++;			
			}			
			return value;
		}
			
		
		return "";
	}

	public void setMSISDN(int mSISDNInfo,String mSISDN) {
		BCDNumber msisdn = new BCDNumber(mSISDN, "f");		
		MSISDN.setTagValue(ProtoOperations.concatArrays(new byte []{(byte)mSISDNInfo}, msisdn.getByteArray()));
		IMSI.setVisible(false);
	}
	

	
	public TcapConstructor getRootComponent(){
		return Invoke;
	}
	
	
	
}
